package com.example.hxpc.guidancemanagement.fragment;


import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.example.hxpc.guidancemanagement.R;
import com.example.hxpc.guidancemanagement.tools.LogoutT;
import com.example.hxpc.guidancemanagement.tools.dataTools.OkHttpTools;
import com.zhy.http.okhttp.OkHttpUtils;

/**
 * Created by tao on 2017/11/26.
 * 注册Frament
 */

public class RegisterFrament extends Fragment implements View.OnClickListener{
    private View rootView;
    private EditText edt_phone , edt_pass , edt_code ,edt_name;
    private Button bu_register;
    private OkHttpTools okHttpTools = new OkHttpTools();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null){
            rootView = inflater.inflate(R.layout.frament_register,null);
        }
        initView(rootView);
        return rootView;
    }

    public void initView(View rootView){
        edt_phone = (EditText) rootView.findViewById(R.id.reg_edit_1);
        setIconSize(R.drawable.phone,edt_phone);
        edt_pass = (EditText) rootView.findViewById(R.id.reg_edit_2);
        setIconSize(R.drawable.register_pass,edt_pass);
        edt_code = (EditText) rootView.findViewById(R.id.reg_edit_3);
        setIconSize(R.drawable.code,edt_code);
        edt_name = (EditText) rootView.findViewById(R.id.reg_edit_4);
        setIconSize(R.drawable.name,edt_name);
        bu_register = (Button) rootView.findViewById(R.id.register);
        bu_register.setOnClickListener(this);
    }

    //控制图标的大小
    public void setIconSize(int p , EditText editText){
        Drawable drawable = getResources().getDrawable(p);
        drawable.setBounds(10,0,50,50);
        editText.setCompoundDrawables(drawable,null,null,null);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.register:
                LogoutT.logout("789798");
                okHttpTools.login(getActivity(),edt_phone.getText().toString(),edt_pass.getText().toString());
                break;
        }
    }
}
